package com.system.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.common.utils.DateUtil;
import com.system.domain.T_rate;
//import com.system.mapper.T_rateMapper;
import com.system.service.T_rateService;

@Controller
@RequestMapping("/t_rate")

public class T_rateController
{
	private static Logger log = Logger.getLogger(T_rateController.class.getName());

	@Resource
    private T_rateService t_rateService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_rateMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_rate信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_rate")
	@ResponseBody
	public Pg getAllT_rate(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_rate t_rate = new T_rate();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_rate.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("ratename")!=null&&!"".equals(request.getParameter("ratename"))){
	        	t_rate.setRatename(request.getParameter("ratename"));
	        }
			if(request.getParameter("memo")!=null&&!"".equals(request.getParameter("memo"))){
	        	t_rate.setMemo(request.getParameter("memo"));
	        }
			if(request.getParameter("bankcode")!=null&&!"".equals(request.getParameter("bankcode"))){
	        	t_rate.setBankcode(request.getParameter("bankcode"));
	        }
			if(request.getParameter("ratetype")!=null&&!"".equals(request.getParameter("ratetype"))){
	        	t_rate.setRatetype(request.getParameter("ratetype"));
	        }
			if(request.getParameter("ratetype2")!=null&&!"".equals(request.getParameter("ratetype2"))){
	        	t_rate.setRatetype2(request.getParameter("ratetype2"));
	        }
			if(request.getParameter("ratetype3")!=null&&!"".equals(request.getParameter("ratetype3"))){
	        	t_rate.setRatetype3(request.getParameter("ratetype3"));
	        }
			if(request.getParameter("ratevalue")!=null&&!"".equals(request.getParameter("ratevalue"))){
	        	t_rate.setRatevalue(request.getParameter("ratevalue"));
	        }
			if(request.getParameter("limit")!=null&&!"".equals(request.getParameter("limit"))){
	        	t_rate.setLimit(request.getParameter("limit"));
	        }
			if(request.getParameter("distount")!=null&&!"".equals(request.getParameter("distount"))){
	        	t_rate.setDistount(request.getParameter("distount"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_rate.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_rate.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_rate.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("status")!=null&&!"".equals(request.getParameter("status"))){
	        	t_rate.setStatus(request.getParameter("status"));
	        }
			if(request.getParameter("batchdate")!=null&&!"".equals(request.getParameter("batchdate"))){
	        	t_rate.setBatchdate(request.getParameter("batchdate"));
	        }
			if(request.getParameter("systemid")!=null&&!"".equals(request.getParameter("systemid"))){
	        	t_rate.setSystemid(request.getParameter("systemid"));
	        }
      	    if(request.getParameter("rateid")!=null&&!"".equals(request.getParameter("rateid"))){
	        	t_rate.setRateid(new Integer(request.getParameter("rateid")));
	        }

	        if(request.getParameter("starttime")!=null&&!"".equals(request.getParameter("starttime"))){
	        	t_rate.setStarttime(DateUtil.parseByDefaultDatePattern(request.getParameter("starttime")));
	        }
	        if(request.getParameter("endtime")!=null&&!"".equals(request.getParameter("endtime"))){
	        	t_rate.setEndtime(DateUtil.parseByDefaultDatePattern(request.getParameter("endtime")));
	        }
	        t_rate.setStartNo( startIndex );
	        t_rate.setEndNo( startIndex + pageSize );
	    	List<T_rate> findAll = t_rateService.findAll(t_rate);
	        int totalCount = t_rateService.findCountAll(t_rate);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_rateList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_rateList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_rate信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_rate")
	@ResponseBody
	public JsonVO saveT_rate(T_rate t_rate, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_rateService.save(t_rate)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_rate信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_rate
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_rate")
	@ResponseBody
	public JsonVO updateT_rate(T_rate t_rate, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_rate t_rateTemp = t_rateService.findById(t_rate);
		//t_rateTemp.setXXX(t_rate.getXXX());
		//if(t_rateService.update(t_rateTemp)){

		if(t_rateService.update(t_rate)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_rate单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_rate json格式字符串
	 */
	@RequestMapping("/getT_rate")
	@ResponseBody
	public T_rate getT_rate(Integer id,HttpServletRequest request){
		T_rate t_rate = new T_rate();
		t_rate.setRateid(id);
		return t_rateService.findById(t_rate);
	}

	/**
	 * 5、删除T_rate根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_rate")
	@ResponseBody
	public JsonVO delT_rate(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_rate t_rate = new T_rate();
		t_rate.setRateid(id);

		if(t_rateService.delete(t_rate)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_rate/toT_rateList查询所有数据页面
	 *  return /WEB-INF/views/system/t_rate/t_rateList.jsp
	 */
    @RequestMapping(value = "/toT_rateList")
    public String toT_rateList() {
    	log.debug("------跳转到/WEB-INF/views/system/t_rate/t_rateList.jsp------");
        return "system/t_rate/t_rateList";
    }

	/**
	 * 7、新增、修改、详情页面t_rate/toT_rateCurd跳转
     * system/t_rate/T_rateCurd.jsp
	 */
    @RequestMapping(value = "/toT_rateCurd")
    public String toT_rateCurd() {
    	log.debug("------跳转到/WEB-INF/views/system/t_rate/t_rateCurd.jsp------");
        return "system/t_rate/t_rateCurd";
    }

    /**
	 * 8、批量删除T_rate根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_rateBatch")
	public String delT_rateBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_rate t_rate = new T_rate();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_rate.setRateid(new Integer(ids[i]).intValue());
			t_rateService.delete(t_rate);
		}
		if(j==ids.length){
			log.debug("------t_rate批量删除成功！------");
		}else{
			log.error("------t_rate批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_rate/getAllT_rate";
	}
*/



}









